package org.csu.demo.db.service;

import org.csu.demo.db.domain.Score;
import org.csu.demo.db.persistence.ScoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreServiceImpl implements ScoreService {
    @Autowired
    private ScoreMapper scoreMapper;

    @Override
    public List<Score> getScoresByStudentId(String studentId) {
        return scoreMapper.selectByStudentId(studentId);
    }

    @Override
    public void addScore(Score score) {
        score.setId(null);  // 确保 id 为 null，让数据库自增
        scoreMapper.insert(score);
    }

    @Override
    public void updateScore(Score score) {
        scoreMapper.updateById(score);
    }

    @Override
    public void deleteScore(int id) {
        scoreMapper.deleteById(id);
    }
}
